package com.sgb.kjwl.api;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

import java.lang.reflect.Type;
import java.util.Date;

public class GsonManager {
    private static GsonManager instance = new GsonManager();
    private Gson gson;

    private GsonManager() {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.registerTypeAdapter(Date.class, (JsonDeserializer<Date>) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong()));
        this.gson = gsonBuilder.create();
    }

    public static GsonManager getInstance() {
        return instance;
    }

    public Gson getGson() {
        return gson;
    }
}
